package com.jrh.biz.brand;

import java.util.List;

import com.jrh.dal.BrandDao;
import com.jrh.dal.ImgAdDao;
import com.jrh.domain.common.Page;
import com.jrh.domain.entity.Brand;
import com.jrh.domain.entity.ImgAd;

/**
 * 品牌服务实现
 * 
 * @author yout 2012-7-22 上午10:48:57
 */
public class BrandServiceImpl implements BrandService {

    private BrandDao brandDao;

    private ImgAdDao imgAdDao;

    public void setImgAdDao(ImgAdDao imgAdDao) {
        this.imgAdDao = imgAdDao;
    }

    public void setBrandDao(BrandDao brandDao) {
        this.brandDao = brandDao;
    }

    @Override
    public Page<Brand> listBrandsByCondition(Brand brand, Integer start, Integer pageSize, Long mallId) {
        return brandDao.listByCondition(brand, start, pageSize, mallId);
    }

    @Override
    public void addBrand(Brand brand) {
        brandDao.insert(brand);

    }

    @Override
    public void modifyBrand(Brand brand) {
        brandDao.update(brand);
    }

    @Override
    public Brand getBrandById(long id) {
        Brand brand = brandDao.load(id);
        if (brand == null) {
            return null;
        }
        List<ImgAd> list = imgAdDao.listByCondition(new ImgAd(id, ImgAd.AD_TYPE_BRAND));
        brand.setImgAds(list);
        return brand;
    }

    @Override
    public void delete(long id) {
        brandDao.delete(id);
    }

    @Override
    public Brand getBrandByUserId(long userId) {
        Brand brand = brandDao.getBrandByUserId(userId);
        if (brand == null) {
            return null;
        }
        List<ImgAd> list = imgAdDao.listByCondition(new ImgAd(brand.getId(), ImgAd.AD_TYPE_BRAND));
        brand.setImgAds(list);
        return brand;
    }

}
